home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / sco5x / emd / bin / stop_enl_daemons < prev   
Text File  |  1998-07-01  |  3KB  |  156 lines

  1. #!/bin/sh
  2. #
  3. # Script: stop_enl_daemons
  4. #
  5. # stop_enl_daemons stops all Enlighten daemons 
  6. # (emd, pep, renld, and Events)
  7. #
  8. # Note: I tried to use $* to pass "$procs" around, but
  9. # SCO fails to deal with $* properly in the context of a function.
  10. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  11. # All Rights Reserved.
  12. # mrm July 23, 1997
  13. #
  14.  
  15. PATH=/bin:/usr/bin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH
  16. export PATH
  17.  
  18.  
  19. #
  20. # Display Usage
  21. #
  22. usage() {
  23.     echo "Usage: $appName"
  24. }
  25.  
  26. #
  27. # Put the pid(s) of process(es) from $procs into $pid
  28. #
  29. getPid() {
  30.  
  31.     # Search for:
  32.     # .../bin/renld -v 0
  33.     # .. renld -v0
  34.     # renld
  35.  
  36.     psList=`ps $PSOPTS | egrep -v "$appName|grep|stop_enl_daemons|start_enl_daemons|enl_post_install"` 
  37.     pid=""
  38.  
  39.     for i in $procs ; do
  40.         newpid=`echo "$psList" | egrep "\/$i | $i |[\/ ]$i$" | \
  41.             sed -e 's/^  *//' -e 's/ .*//'`
  42.         pid="$pid $newpid"
  43.     done
  44.     pid=`echo $pid`
  45. }
  46.  
  47. #
  48. # Kill process(es) in $procs. 
  49. #
  50. killProcs() {
  51.     getPid $procs
  52.     if [ -n "$pid" ] ; then
  53.         if [ "$KILLOPTS" = "-9" -o "$KILLOPTS" = "-KILL" ] ; then
  54.             echo
  55.             echo "$appName: Killing the following processes:"
  56.         else
  57.             echo
  58.             echo "$appName: Stopping the following processes:"
  59.         fi
  60.         echo "$psList" | grep PID
  61.         for i in $pid ; do 
  62.             echo "$psList" | egrep "^[     ]*$i "
  63.             kill $KILLOPTS $i
  64.         done
  65.     else
  66.         echo "$appName: No Enlighten daemons are active."
  67.         echo "$appName: Checking for licenseing daemons..."
  68.     fi
  69. }
  70.  
  71. #
  72. # Kill Stubborn processes in $procs
  73. # killStubbornProc waits for WAIT_CYCLES before kill -KILL'ing.
  74. killStubbornProcs() {
  75.     WAIT_CYCLES=${WAIT_CYCLES:-10}
  76.     cyclesWaited=0
  77.     $ECHO "$appName: Waiting for daemons to shut down.\c"
  78.  
  79.     while [ $cyclesWaited -lt $WAIT_CYCLES ] ; do
  80.         cyclesWaited=`expr $cyclesWaited + 1`
  81.         sleep 1
  82.         getPid
  83.         if [ -z "$pid" ] ; then
  84.             break
  85.         else
  86.             $ECHO ".\c"
  87.         fi
  88.     done
  89.     echo
  90.  
  91.     if [ $cyclesWaited -eq $WAIT_CYCLES ] ; then
  92.         KILLOPTS="-9"
  93.         killProcs
  94.     fi
  95. }
  96.  
  97. #
  98. # -=-=-=-=-=-=-=-= Start of Main Program -=-=-=-=-=-=-=-=-=-
  99. #
  100.  
  101. appName=`basename $0`
  102.  
  103. #
  104. # Ensure the user is root
  105. #
  106. USER_ID=`id | tr "\(" "=" | cut "-d=" -f2`
  107.  
  108. if [ ! $USER_ID = 0 ] ; then
  109.     echo "### $appName must be run by the 'root' superuser."
  110.     echo "    Please su to root and try again."
  111.     exit 2
  112. fi
  113.  
  114. #
  115. # Deal with bsd ps
  116. #
  117.  
  118. ECHO=echo
  119.  
  120. PSOPTS="-e"
  121. PIDCOLUMN=1
  122.  
  123. OS=`uname -s`
  124. REV=`uname -r`
  125.  
  126. export OPTS PIDCOLUMN ECHO pid psList procs
  127.  
  128. if [ "$OS" = "SunOS" ] ; then
  129.     case "$REV" in 4.1.* )
  130.         PSOPTS="-agxww" 
  131.         if [ -x /usr/5bin/echo ] ; then
  132.             ECHO=/usr/5bin/echo
  133.         fi
  134.         ;;
  135.     esac
  136. fi
  137.  
  138. #
  139. # Stop the daemons.
  140. #
  141.  
  142. KILLOPTS="-15"
  143. WAIT_CYCLES=10 # About 10 seconds.
  144.  
  145. procs="AgentMon renld pep emdd renldc AgentENL"
  146.  
  147. killProcs 
  148. getPid 
  149. if [ -n "$pid" ] ; then 
  150.     killStubbornProcs
  151. fi
  152.  
  153. echo "$appName: Finished."
  154.